package com.neuedu.carsystem.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.JOptionPane;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.neuedu.carsystem.model.Admin;
import com.neuedu.carsystem.service.AdminService;
@Controller
@RequestMapping("/admin")
public class AdminAction {
	
	@Autowired
	private AdminService adminService;
	
	
	//登录
		@RequestMapping("/adminlogin")
		public void login(Admin admin,
				    HttpServletRequest request,HttpServletResponse response) throws Exception{
			
			//调用业务逻辑层进行处理，进行用户的登录
			Admin ret = adminService.findAdminByName(admin);
			
			if(ret!=null){
				//登录成功 - 记录用户的session会话中，并跳转Dao管理首页
				request.getSession().setAttribute("LOGIN_USER", ret);
				
				response.sendRedirect(request.getContextPath()+"/pages/index.jsp");
			}else{
				//登录失败,返回登录页面
				JOptionPane.showMessageDialog(null, "账户名和密码不对，请重新输入！"); 
				response.sendRedirect(request.getContextPath()+"/login.jsp");
			}
		}
		
	
	//查询所有
		/*@RequestMapping("/findname")
		public String findNameById(HttpServletRequest request,HttpServletResponse response) throws Exception{
	    	String ano = request.getParameter("ano");
	        String username = adminService.findName(ano);
	        System.out.println(username);
	        return "index";
	    }*/

}
